import 'package:changxindianzishangwu/util/toast.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:tencent_im_sdk_plugin/tencent_im_sdk_plugin.dart';

import '../../home_page.dart';

//申请添加好友
class UserFirePage extends StatefulWidget {
  int type;
  var userId;
  var nickName;
  UserFirePage({Key key, this.userId, this.nickName, this.type = 1})
      : super(key: key);

  @override
  _UserFirePageState createState() => _UserFirePageState();
}

class _UserFirePageState extends State<UserFirePage> {
  String friendRemark;
  String addWording;

  add() {
    print(widget.userId);

    print(friendRemark);
    print(addWording);
    EasyLoading.show(status: "添加中...");

    TencentImSDKPlugin.v2TIMManager.v2TIMFriendshipManager
        .addFriend(
            userID: widget.userId,
            addType: 2,
            remark: friendRemark ?? "",
            addWording: addWording,
            addSource: widget.type == 1 ? "id" : "other")
        .then((value) {
      if (value.code == 0) {
        EasyLoading.dismiss();
        Get.offAll(() => HomePage(
              pageIndex: 1,
            ));
        //Get.to(AddFriendPage());
        showToast('添加发送成功');
      } else {
        EasyLoading.dismiss();
        showToast('添加发送失败');
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        elevation: 0,
        centerTitle: true,
        title: Text(
          "申请添加好友",
          style:
              TextStyle(fontSize: ScreenUtil().setSp(16), color: Colors.black),
        ),
      ),
      body: Container(
          color: Colors.white,
          child: GestureDetector(
            onTap: () {
              FocusScope.of(context).requestFocus(FocusNode());
            },
            child: ListView(
              children: [
                Container(
                  margin: EdgeInsets.only(
                      top: ScreenUtil().setHeight(10),
                      left: ScreenUtil().setWidth(15)),
                  child: Text(
                    "发送添加好友申请",
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(14),
                      color: Color.fromRGBO(153, 153, 153, 1),
                    ),
                  ),
                ),
                Container(
                  child: Container(
                    height: ScreenUtil().setHeight(150),
                    width: ScreenUtil().setWidth(345),
                    padding: EdgeInsets.only(left: 20),
                    margin: EdgeInsets.only(
                        left: ScreenUtil().setWidth(10),
                        top: ScreenUtil().setHeight(10),
                        right: ScreenUtil().setWidth(15)),
                    decoration: BoxDecoration(
                        color: Color.fromRGBO(241, 241, 241, 1),
                        borderRadius: BorderRadius.circular(6)),
                    child: TextField(
                      maxLines: 5,
                      maxLength: 46,
                      cursorColor: Colors.lightBlueAccent,
                      keyboardType: TextInputType.name,
                      autofocus: false,
                      onChanged: (value) {
                        addWording = value;
                      },
                      decoration: InputDecoration(
                          border: InputBorder.none,
                          hintText: "好友申请",
                          hintStyle: TextStyle(
                            fontSize: 15,
                          )),
                    ),
                  ),
                ),
                // Container(
                //   margin: EdgeInsets.only(
                //       top: ScreenUtil().setHeight(18),
                //       left: ScreenUtil().setWidth(15)),
                //   child: Text(
                //     "设置备注",
                //     style: TextStyle(
                //       fontSize: ScreenUtil().setSp(14),
                //       color: Color.fromRGBO(153, 153, 153, 1),
                //     ),
                //   ),
                // ),
                // Container(
                //   child: Container(
                //     height: ScreenUtil().setHeight(50),
                //     width: ScreenUtil().setWidth(345),
                //     padding: EdgeInsets.only(left: 20, top: 5),
                //     margin: EdgeInsets.only(
                //         left: ScreenUtil().setWidth(10),
                //         top: ScreenUtil().setHeight(10),
                //         right: ScreenUtil().setWidth(15)),
                //     decoration: BoxDecoration(
                //         color: Color.fromRGBO(241, 241, 241, 1),
                //         borderRadius: BorderRadius.circular(6)),
                //     child: TextField(
                //       cursorColor: Colors.lightBlueAccent,
                //       keyboardType: TextInputType.name,
                //       autofocus: false,
                //       onChanged: (value) {
                //         friendRemark = value;
                //       },
                //       decoration: InputDecoration(
                //           border: InputBorder.none,
                //           hintText: "好友备注",
                //           hintStyle: TextStyle(
                //             fontSize: 15,
                //           )),
                //     ),
                //   ),
                // ),
                //todo 分类隐藏
                // Container(
                //   margin: EdgeInsets.only(
                //       top: ScreenUtil().setHeight(18),
                //       left: ScreenUtil().setWidth(15)),
                //   child: Text(
                //     "选择标签",
                //     style: TextStyle(
                //       fontSize: ScreenUtil().setSp(14),
                //       color: Color.fromRGBO(153, 153, 153, 1),
                //     ),
                //   ),
                // ),
                // Container(
                //   child: Container(
                //     height: ScreenUtil().setHeight(50),
                //     width: ScreenUtil().setWidth(345),
                //     padding: EdgeInsets.only(left: 20, top: 5),
                //     margin: EdgeInsets.only(
                //         left: ScreenUtil().setWidth(10),
                //         top: ScreenUtil().setHeight(10),
                //         right: ScreenUtil().setWidth(15)),
                //     decoration: BoxDecoration(
                //         color: Color.fromRGBO(241, 241, 241, 1),
                //         borderRadius: BorderRadius.circular(6)),
                //     child: TextField(
                //       cursorColor: Colors.lightBlueAccent,
                //       keyboardType: TextInputType.name,
                //       autofocus: false,
                //       onChanged: (value) {},
                //       decoration: InputDecoration(
                //           border: InputBorder.none,
                //           hintText: "未选择",
                //           hintStyle: TextStyle(
                //             fontSize: 15,
                //           )),
                //     ),
                //   ),
                // ),
                InkWell(
                  onTap: () {
                    add();
                  },
                  child: Container(
                    margin: EdgeInsets.only(
                      left: ScreenUtil().setWidth(98),
                      top: ScreenUtil().setHeight(86),
                      right: ScreenUtil().setWidth(98),
                    ),
                    alignment: Alignment.center,
                    height: ScreenUtil().setHeight(44),
                    width: ScreenUtil().setWidth(150),
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(6),
                      color: Color.fromRGBO(0, 220, 169, 1),
                    ),
                    child: Text(
                      "发送",
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(15),
                        color: Colors.white,
                      ),
                    ),
                  ),
                )
              ],
            ),
          )),
    );
  }
}
